package my.springboot3.utils;

public class ThreadLocalUtil {
    // 创建 ThreadLocal 本地线程
    private static final ThreadLocal<Object> THREAD_LOCAL = new ThreadLocal<>();
    /**
     * 存储当前线程信息,默认存放(int) id
      */
    public static  <T> void set(T value) {
        THREAD_LOCAL.set(value);
    }
    /**
     * 获取当前线程信息,默认存放(int) id
     */
    @SuppressWarnings("unchecked")
    public static <T> T get() {
        return (T) THREAD_LOCAL.get();
    }

    // 清除当前线程信息，不是所有
    public static void clear() {
        THREAD_LOCAL.remove();
    }
}

